import 'package:safetymonitor/app/components/custom_app_bar.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/ext/widget_extension.dart';
import 'package:safetymonitor/modules/home/enterprise/a_enterprise_controller.dart';
import 'package:safetymonitor/modules/home/enterprise/company_info/company_info_view.dart';
import 'package:safetymonitor/modules/home/enterprise/emergency_plan/emergency_plan_view.dart';
import 'package:safetymonitor/modules/home/enterprise/people_or_papers/people_or_papers_view.dart';

/// 一企一档
class OneEnterprise extends StatelessWidget {
  OneEnterprise({super.key});

  final controller = Get.put(EnterpriseController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<EnterpriseController>(
      init: controller,
      builder: (_) {
        return
          // Stack(
          // children: [
            Scaffold(
              appBar: CustomAppBar(
                titleText: '一企一档',
                actions: [
                  //只有主公司才显示
                  //当前账号单位是不是主公司
                  //是的话才可以选择子公司
                  Visibility(visible: controller.currentMainCompany == controller.userCompanyName, child: _company()),
                ],
              ),
              body: DefaultTabController(
                length: controller.title.length,
                child: Column(
                  children: [
                    TabBar(
                      tabs: controller.title.map((e) => Tab(text: e)).toList(),
                    ),
                    Expanded(
                      child: TabBarView(
                        children: [
                          CompanyInfoPage(),
                          PeopleOrPapersPage(),
                          EmergencyPlanPage(),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            );
            // NestingBottomCloseOnSwipeDownWidget(
            //   topHeight: 350,
            //   scrollController: controller.controller,
            //   key: controller.globalKey,
            //   backgroundColor: Colors.white,
            //   child: MediaQuery.removePadding(
            //     context: context,
            //     removeTop: true, //去除顶部的空白
            //     child: ListView.separated(
            //       controller: controller.controller,
            //       physics: const ClampingScrollPhysics(),
            //       itemCount: controller.nameList.length,
            //       itemBuilder: (context, index) {
            //         return ListTile(
            //           title: Center(child: Text(controller.nameList[index].name)),
            //         ).clickOnce(() {
            //           controller.globalKey.currentState?.startSlideOutAnimation();
            //           controller.selectCompany=controller.nameList[index].name;
            //           Get.find<CompanyInfoController>().information();
            //           Get.find<EmergencyPlanController>().globalKey.currentState?.onRefresh();
            //           Get.find<PeopleOrPapersController>().globalKey.currentState?.onRefresh();
            //           controller.update();
            //         });
            //       },
            //       separatorBuilder: (context, index) {
            //         return Divider(height: 0.5.w, color: const Color(0xFFEAF2FA));
            //       },
            //     ),
            //   ),
            //   voidCallback: () {
            //     // AppToast.showSuccess('');
            //   },
            // )
          // ],
        // );
      },
    );
  }

  ///公司
  Widget _company() {
    // return SizedBox(
    //     width: 120.0,
    //     height: 30.0,
    //     child: DropdownButtonFormField<String>(
    //       isExpanded: true,
    //       iconSize: 20,
    //       style: const TextStyle(fontSize: 15, color: Colors.black),
    //       decoration: const InputDecoration(contentPadding: EdgeInsets.only(left: 5, right: 5), border: OutlineInputBorder(gapPadding: 1), labelText: ''),
    //       // 设置默认值
    //       value: '请选择',
    //       // 选择回调
    //       onChanged: (String? newPosition) {
    //         controller.selectCompany = newPosition!;
    //         Get.find<CompanyInfoController>().information();
    //         Get.find<EmergencyPlanController>().enterpriseEmergencyPlan(1, 20);
    //         Get.find<PeopleOrPapersController>().enterpriseStaffPage(1, 20);
    //       },
    //       // 传入可选的数组
    //       items: controller.companyList.map((String sex) {
    //         return DropdownMenuItem(value: sex, child: Text(sex));
    //       }).toList(),
    //     ));
    return Container(
      width: 120.0,
      height: 30.0,
      margin: const EdgeInsets.only(right: 10),
      decoration: BoxDecoration(color: Colors.white, border: Border.all(color: const Color(0xffDCE1EA)), borderRadius: BorderRadius.circular(6)),
      child: Row(
        children: [
          const SizedBox(
            width: 12,
          ),
          Expanded(
              child: Text(
            controller.getString(),
                // controller.selectCompany.isNotEmpty? controller.selectCompany:'公司名',
            style: TextStyles.grey_14,
            maxLines: 1,
          )),
          const Icon(
            Icons.keyboard_arrow_down,
            color: AppColors.font_color_gray,
          ),
          const SizedBox(
            width: 8,
          ),
        ],
      ),
    )
    //     .clickOnce(() {
    //   // controller.globalKey.currentState?.startReturnToOriginalPositionAnimation();
    //   showModalBottomSheet(
    //     context: Get.context!,
    //     showDragHandle: true,
    //     builder: (context) {
    //     return Container(
    //       // height: 300,
    //       child: ListView.separated(
    //         itemCount: controller.nameList.length,
    //         itemBuilder: (context, index) {
    //           return ListTile(
    //             title: Center(child: Text(controller.nameList[index].name)),
    //           ).clickOnce(() {
    //             Get.back();
    //             controller.globalKey.currentState?.startSlideOutAnimation();
    //             controller.selectCompany=controller.nameList[index].name;
    //             Get.find<CompanyInfoController>().information();
    //             Get.find<EmergencyPlanController>().globalKey.currentState?.onRefresh();
    //             Get.find<PeopleOrPapersController>().globalKey.currentState?.onRefresh();
    //             controller.update();
    //           });
    //         },
    //         separatorBuilder: (context, index) {
    //           return Divider(height: 1.w, color: Colors.grey[300]);
    //         },
    //       ),
    //     );
    //   },
    //   );
    // });
    .clickOnce(controller.selectCompanyOn);
  }
}
